//
//  CoserCell.m
//  Double
//
//  Created by 袁庆秋 on 15/5/22.
//  Copyright (c) 2015年 袁庆秋. All rights reserved.
//

#import "CoserCell.h"
#import "QBFlatButton.h"
#import "CoserModel.h"
#import <UIImageView+WebCache.h>
@implementation CoserCell

- (void)dealloc
{
    [_model release];
    [_countBtn release];
    [_showImage release];
    [_nameLabel release];
    [super dealloc];
}
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
//显示图片
        self.showImage = [[UIImageView alloc] initWithFrame:CGRectMake(5, 5, self.frame.size.width - 10, self.frame.size.height - 50)];
        self.showImage.userInteractionEnabled = YES;
        [self addSubview:self.showImage];
        [self.showImage release];
        
        self.nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(5, self.frame.size.height - 50, self.frame.size.width, 30)];
        [self addSubview:self.nameLabel];
        [self.nameLabel release];
        
//点赞按钮
        self.countBtn = [QBFlatButton buttonWithType:UIButtonTypeCustom];
        self.countBtn.frame = CGRectMake(5, self.frame.size.height - 20, self.frame.size.width, 20);
        self.countBtn.faceColor = [UIColor colorWithRed:86.0/255.0 green:161.0/255.0 blue:217.0/255.0 alpha:1.0];
        self.countBtn.sideColor = [UIColor colorWithRed:79.0/255.0 green:127.0/255.0 blue:179.0/255.0 alpha:1.0];
        self.countBtn.radius = 8.0;
        self.countBtn.margin = 4.0;
        self.countBtn.depth = 3.0;
        
        [self.countBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [self.countBtn setImage:[UIImage imageNamed:@"1.png"] forState:UIControlStateNormal];
        [self.countBtn addTarget:self action:@selector(countAdd:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:self.countBtn];
        [self.countBtn release];
    }
    return self;
}


//将自定义cell的值都赋给model
- (void)setModel:(CoserModel *)model
{
    [self.showImage sd_setImageWithURL:[NSURL URLWithString:model.pic] placeholderImage:[UIImage imageNamed:@"placeholder.jpg"] options:SDWebImageRetryFailed];
    self.nameLabel.text = model.name;
    [self.countBtn setTitle:[NSString stringWithFormat:@"%@",model.num] forState:UIControlStateNormal];
}

//点赞按钮点一次数值就加一， 初始值是从网上取到的数据
- (void)countAdd:(UIButton *)button
{
    NSString *str = [button titleForState:UIControlStateNormal];
    int num = [str intValue];
    num++;
    [button setTitle:[NSString stringWithFormat:@"%d",num] forState:UIControlStateNormal];
}


@end
